<?php

namespace zhtfrontend\models\datas;

use Yii;
use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
 * This is the model class for table "{{%mechanic_settlement_subsidy}}".
 *
 * @property integer $id
 * @property integer $mechanic_settlement_id
 * @property string $money
 * @property string $remark
 * @property integer $updated_at
 * @property integer $created_at
 */
class MechanicSettlementSubsidy extends \zhtfrontend\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%mechanic_settlement_subsidy}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['mechanic_settlement_id', 'updated_at', 'created_at'], 'integer'],
            [['money'], 'number'],
            [['remark'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('zhtfrontend', '自增id'),
            'mechanic_settlement_id' => Yii::t('zhtfrontend', '结算id'),
            'money' => Yii::t('zhtfrontend', '金额'),
            'remark' => Yii::t('zhtfrontend', '备注'),
            'updated_at' => Yii::t('zhtfrontend', '修改时间'),
            'created_at' => Yii::t('zhtfrontend', '添加时间'),
        ];
    }

    public function fields()
    {
        $fields = parent::fields();
        $fields['created_at'] = function () {
            return \Yii::$app->formatter->asDate($this->created_at);
        };
        $fields['updated_at'] = function () {
            return \Yii::$app->formatter->asDate($this->updated_at);
        };
        return $fields;
    }

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ]);
    }
}
